package com.cimp.controller.c2;

import com.cimp.domain.c2.DistributeMsg;
import com.cimp.domain.c2.SoapConfig;
import com.cimp.domain.common.Result;
import com.cimp.domain.iqy.Virtual;
import com.cimp.service.c2.UpstreamService;
import com.cimp.util.iqy.IqyContants;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Objects;

/**
 * [简要描述]:
 * [详细描述]:
 *
 * @author huojinhao
 * @date 2019/1/7
 */
@RestController
public class UpstreamController {

    @Resource
    private UpstreamService upstreamService;

    /**
     * 增加接口模拟
     * @return
     */
    @RequestMapping(value = "upstream/soapconfig/add")
    public Result insertSoapConfig(SoapConfig soapConfig) {
        if (Objects.isNull(soapConfig.getId())) {
            upstreamService.insertSoapConfig(soapConfig);
        }else{
            upstreamService.updateSoapConfig(soapConfig);
        }
        return Result.success();
    }

    /**
     * 获取虚拟接口列表
     */
    @RequestMapping(value = "upstream/soapconfig")
    public List<SoapConfig> querySoapConfigList(){
        List<SoapConfig> soapConfigs = upstreamService.querySoapConfigList();
        return soapConfigs;
    }

    /**
     * 删除虚拟接口
     */
    @RequestMapping(value = "upstream/soapconfig/delete")
    public Result deleteSoapConfig(Integer id){
        upstreamService.deleteSoapConfig(id);
        return Result.success();
    }

    /**
     * 下发
     */
    @RequestMapping(value = "/upstream/distribute")
    public Result distribute(SoapConfig soapConfig) throws RemoteException, ServiceException, MalformedURLException {
        try {
            upstreamService.distribute(soapConfig);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }

    }


    /**
     * 获取下发详情列表
     */
    @RequestMapping(value = "/upstream/distribute/list")
    public List<DistributeMsg> queryDistributeMsgList(){
        List<DistributeMsg> distributeMsgs = upstreamService.queryDistributeMsgList();
        return distributeMsgs;
    }

}
